package com.example.materialtest

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.view.View
import android.view.Window
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity


class WelcomeActivity : Activity() {
    var i=0
    var welcome_daojishi : androidx.percentlayout.widget.PercentRelativeLayout? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.activity_welcome)
        textView = findViewById<View>(R.id.daojishi) as TextView
        animation = AnimationUtils.loadAnimation(this, R.anim.animation_text)
        handler.sendEmptyMessageDelayed(0, 1000)
        welcome_daojishi = findViewById<View>(R.id.welcome_daojishi) as androidx.percentlayout.widget.PercentRelativeLayout
        welcome_daojishi!!.setOnClickListener {
            i=1
            val intent = Intent(this, enter::class.java)
            startActivity(intent)
            finish()
        }
    }
    private var textView: TextView? = null
    private var count = 4
    private get() {
        field--
        if (field == 0) {
            if(i==0){
                val intent = Intent(this, enter::class.java)
                startActivity(intent)
                finish()
            }

        }
        return field
    }
    private var animation: Animation? = null

    //进行一个消息的处理
    @SuppressLint("HandlerLeak")
    private val handler: Handler = object : Handler() {
        override fun handleMessage(msg: Message) {
            if (msg.what == 0) {
                textView!!.text = count.toString() + ""
                this.sendEmptyMessageDelayed(0, 1000)
                animation?.reset()
                textView!!.startAnimation(animation)
            }
        }
    }
}